"""
根据身份证查询客户号
"""
from db_fixture import mycat_link


# 客户信息关联表中查询客户号customerNo
def select(idNo):
    # 使用cursor()方法获取操作游标
    cursor = mycat_link.db().cursor()
    # sql 查询语句
    sql = "SELECT * from tb_customer_ids_relation WHERE ids = %s ORDER BY ID DESC LIMIT 1" % idNo
    try:
        # 执行SQL语句
        cursor.execute(sql)
        # 接收全部返回结果行
        results = cursor.fetchall()
        customerNo = results[0][2]
        # print(customerNo)
    except Exception as e:
        raise e
    finally:
        mycat_link.db().close()
    # 关闭连接
    mycat_link.db().close()

    return customerNo


if __name__ == '__main__':
    select(idNo='620423198812141166')
